﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:graphWpf="clr-namespace:theeg.GraphWpf"
    xmlns:models="clr-namespace:theeg.GraphWpf.Models"
    xmlns:views="clr-namespace:theeg.GraphWpf.Views">

    <views:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"></views:BooleanToVisibilityConverter>
    
    <DataTemplate x:Key="NodeRoundRectTemplate" DataType="models:INode">
        <Grid Width="{Binding Width}" Height="{Binding Height}">
            <Rectangle RadiusX="5" RadiusY="5"
                                   Fill="{Binding Background}"
                                   Stroke="{Binding Stroke}"
                                   Stretch="Fill"
                                   />
            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"
                                   Text="{Binding Path=Text}" MaxHeight="{Binding Height}"
                                   Foreground="{Binding Path=Foreground}" TextWrapping="Wrap"
                                   />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="NodeRectangleTemplate" DataType="models:INode">
        <Grid Width="{Binding Width}" Height="{Binding Height}">
            <Rectangle RadiusX="0" RadiusY="0"
                                   Fill="{Binding Background}"
                                   Stroke="{Binding Stroke}"
                                   Stretch="Fill"
                                   />
            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"
                                   Text="{Binding Path=Text}" MaxHeight="{Binding Height}"
                                   Foreground="{Binding Path=Foreground}" TextWrapping="Wrap"
                                   />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="NodeCircleTemplate" DataType="models:INode">
        <Grid Width="{Binding Width}" Height="{Binding Height}">
            <Ellipse Fill="{Binding Background}"
                                   Stroke="{Binding Stroke}"
                                   Stretch="Fill"
                                   />
            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"
                                   Text="{Binding Path=Text}"
                                   Foreground="{Binding Path=Foreground}" TextWrapping="Wrap"
                                   />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="NodeCaretTemplate" DataType="models:INode">
        <Grid Width="{Binding Width}" Height="{Binding Height}">
            <Ellipse Fill="{Binding Background}"
                                   Stroke="{Binding Stroke}"
                                   Stretch="Fill"
                                   />
            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"
                                   Text="{Binding Path=Text}"
                                   Foreground="{Binding Path=Foreground}" TextWrapping="Wrap"
                                   />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="NodeTrianglePeakUpTemplate" DataType="models:INode">
        <Grid Width="{Binding Width}" Height="{Binding Height}">
            <Ellipse Fill="{Binding Background}"
                                   Stroke="{Binding Stroke}"
                                   Stretch="Fill"
                                   />
            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"
                                   Text="{Binding Path=Text}"
                                   Foreground="{Binding Path=Foreground}" TextWrapping="Wrap"
                                   />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="NodeTrianglePeakDownTemplate" DataType="models:INode">
        <Grid Width="{Binding Width}" Height="{Binding Height}">
            <Ellipse Fill="{Binding Background}"
                                   Stroke="{Binding Stroke}"
                                   Stretch="Fill"
                                   />
            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"
                                   Text="{Binding Path=Text}"
                                   Foreground="{Binding Path=Foreground}" TextWrapping="Wrap"
                                   />
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="NodeNoneTemplate" DataType="models:Node">
        <Grid Width="{Binding Width}" Height="{Binding Height}">
            <TextBlock HorizontalAlignment="Center" VerticalAlignment="Center"
                                   Text="{Binding Path=Text}"
                                   Foreground="{Binding Path=Foreground}" TextWrapping="Wrap"
                                   />
        </Grid>
    </DataTemplate>

    <views:NodeShapeToTemplateConverter x:Key="NodeShapeToTemplateConverter"
                                        RectangleTemplate="{StaticResource NodeRectangleTemplate}"
                                        RoundRectTemplate="{StaticResource NodeRoundRectTemplate}"
                                        CircleTemplate="{StaticResource NodeCircleTemplate}"
                                        CaretTemplate="{StaticResource NodeCircleTemplate}"
                                        TrianglePeakUpTemplate="{StaticResource NodeTrianglePeakUpTemplate}"
                                        TrianglePeakDownTemplate="{StaticResource NodeTrianglePeakDownTemplate}"
                                        NoneTemplate="{StaticResource NodeNoneTemplate}"
                                        >
    </views:NodeShapeToTemplateConverter>

    <views:TransitionToGeometryConverter x:Key="TransitionToGeometryConverter"/>
    <views:TransitionToTextGeometryConverter x:Key="TransitionToTextGeometryConverter"/>

    <Style TargetType="views:NodePresenter">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="views:NodePresenter">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="Disabled">
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverVisual"
                                    Storyboard.TargetProperty="Visibility" Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" >
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ContentControl x:Name="NodeContent" Content="{TemplateBinding Data}" FontWeight="Regular"
                                        ContentTemplate="{Binding Path=Data, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource NodeShapeToTemplateConverter}, Mode=OneWay}">
                        </ContentControl>
                        <Rectangle x:Name="MouseOverVisual" RadiusX="5" RadiusY="5" Margin="-2" Fill="#01FFFFFF" Visibility="{Binding Data.IsHighlighted, Converter={StaticResource BooleanToVisibilityConverter},
                            RelativeSource={RelativeSource TemplatedParent}}" StrokeThickness="3"
                                   Stroke="{Binding Path=Data.Highlight, RelativeSource={RelativeSource TemplatedParent}}">
                            <Rectangle.ToolTip>
                                <TextBlock Text="{Binding Path=Data.Text, RelativeSource={RelativeSource TemplatedParent}}"></TextBlock>
                            </Rectangle.ToolTip>
                        </Rectangle>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="views:SubGraphPresenter">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="views:SubGraphPresenter">
                    <Grid DataContext="{TemplateBinding Data}" >
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="Disabled">
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="MouseOverVisual"
                                    Storyboard.TargetProperty="Visibility" Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" >
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Rectangle Grid.RowSpan="2" RadiusX="5" RadiusY="5"
                                   Fill="{Binding Background}"
                                   Stroke="{Binding Stroke}"
                                   Stretch="Fill"
                                   />
                        <Rectangle Grid.RowSpan="2" x:Name="MouseOverVisual" RadiusX="5" RadiusY="5" Margin="-2" Fill="#01FFFFFF" 
                                   Visibility="{Binding Data.IsHighlighted, Converter={StaticResource BooleanToVisibilityConverter},
                            RelativeSource={RelativeSource TemplatedParent}}" StrokeThickness="3"
                                   Stroke="{Binding Highlight}">
                            <Rectangle.ToolTip>
                                <TextBlock Text="{Binding Text}"></TextBlock>
                            </Rectangle.ToolTip>
                        </Rectangle>
                        <Grid x:Name="content" Width="{Binding CollapsedWidth}" Height="{Binding CollapsedHeight}" MinWidth="36" HorizontalAlignment="Left">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"></ColumnDefinition>
                                <ColumnDefinition Width="*"></ColumnDefinition>
                            </Grid.ColumnDefinitions>
                            <ToggleButton Width="24" Height="36" Margin="1,4" IsChecked="{Binding IsExpanded, Mode=TwoWay}"
                                      HorizontalAlignment="Left" VerticalAlignment="Top">...</ToggleButton>
                            <TextBlock Grid.Column="1" Text="{Binding Text}" HorizontalAlignment="Center" FontWeight="Regular" TextWrapping="Wrap"
						           VerticalAlignment="Center" MaxHeight="{Binding CollapsedHeight}" Foreground="{Binding Foreground}" TextTrimming="CharacterEllipsis"/>
                        </Grid>
                        <Border x:Name="viewport" Margin="5" Grid.ColumnSpan="2" Grid.Row="1" Background="{Binding Fill}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                Visibility="{Binding IsExpanded, Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}">
                            <Border Margin="5" Width="{Binding ContentWidth}" Height="{Binding ContentHeight}">
                                <Canvas x:Name="sketchPanel" HorizontalAlignment="Left" VerticalAlignment="Top" RenderTransform="{Binding TopLeftContent}">
                                </Canvas>
                            </Border>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="viewport" Property="Visibility" Value="Visible">
                            <Setter TargetName="content" Property="Width" Value="{Binding ContentWidth}"></Setter>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="views:TransitionPresenter">
        <Setter Property="Foreground" Value="{Binding Data.Brush, RelativeSource={RelativeSource Self}}"></Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="views:TransitionPresenter">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal" />
                                <VisualState x:Name="Disabled">
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="transitionPath"
                                    Storyboard.TargetProperty="StrokeThickness" To="6" Duration="0">
                                        </DoubleAnimation>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="transitionPath"
                                    Storyboard.TargetProperty="Stroke" Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0" >
                                                <DiscreteObjectKeyFrame.Value>
                                                    <SolidColorBrush Color="#FFFF3333"></SolidColorBrush>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="textPath"
                                    Storyboard.TargetProperty="Stroke" Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0" >
                                                <DiscreteObjectKeyFrame.Value>
                                                    <SolidColorBrush Color="#FFFF3333"></SolidColorBrush>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Path x:Name="transitionPath" Stroke="{TemplateBinding Foreground}"
                              Fill="{TemplateBinding Foreground}"
                              StrokeThickness="{Binding Data.Magnitude, RelativeSource={RelativeSource TemplatedParent}}"
                              Data="{Binding Data, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource TransitionToGeometryConverter}, Mode=OneWay}"
                              >
                        </Path>
                        <Path x:Name="textPath" Stroke="{TemplateBinding Foreground}"
                              Fill="{TemplateBinding Foreground}"
                              StrokeThickness="1"
                              Data="{Binding Data, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource TransitionToTextGeometryConverter}, Mode=OneWay}"
                              >
                        </Path>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Canvas.ZIndex" Value="1000000"></Setter>
            </Trigger>
            <DataTrigger Binding="{Binding Data.IsHighlighted, RelativeSource={RelativeSource Self}}" Value="True">
                <Setter Property="Canvas.ZIndex" Value="1000000"></Setter>
                <Setter Property="Foreground" Value="#FFFF3333"></Setter>
            </DataTrigger>
        </Style.Triggers>
    </Style>

    <Style TargetType="graphWpf:Sketch">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="graphWpf:Sketch">
                    <Grid Background="{TemplateBinding Background}" x:Name="LayoutRoot"
                            >
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"></RowDefinition>
                            <RowDefinition Height="Auto"></RowDefinition>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"></ColumnDefinition>
                            <ColumnDefinition Width="Auto"></ColumnDefinition>
                        </Grid.ColumnDefinitions>
                        <Border x:Name="viewport" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="#01000000">
                            <Canvas x:Name="sketchPanel" HorizontalAlignment="Center" VerticalAlignment="Center">
                            </Canvas>
                        </Border>

                        <ScrollBar Grid.Row="1" Orientation="Horizontal" x:Name="horizontalScrollBar"></ScrollBar>
                        <ScrollBar Grid.Column="1" Orientation="Vertical" x:Name="verticalScrollBar"></ScrollBar>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
